#export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

target=main-server.jar

pid=`ps aux | grep ${target} | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
  echo "Stopping Spring Application pid=$pid"
  kill -9 $pid
fi

export BUILD_ID=dontKillMe
echo "Starting Spring Application..."

cd /home/ubuntu/main-server

# log-`date +%Y-%m-%d-%H-%M-%S`.log
logfile=log-`date +%Y-%m`.log


echo "" >> $logfile
echo "=========================================================" >> $logfile
echo "" >> $logfile

DB_URL="mongodb://$dbUser:$dbPass@$dbUrl/collection?$dbParams" \
env="test" \
nohup /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Xmx300m -jar $target >> $logfile 2>&1 &

# nohup /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java -Xmx300m -jar $target &>> $logfile &